<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .tab_list{
            border: 1px solid #f5f1efc5;
            height: 50px;
            background-color: #f5f1efc5;
        }
        ul li{
            list-style-type: none;
            float: left;
            margin-left: 10px;
        }
        .current{
            background-color: red;
            color: white;
        }
        .item{
            display: none;
        }
        .bianshe{
            background-color: red;
            color: white;
        }
    </style>
</head>
<body>
    <div class="tab"> 
        <div class="tab_list">
            <ul>
                <li class="current">商品介绍</li>
                <li>规格与包装</li>
                <li>售后保障</li>
                <li>商品评价</li>
                <li>手机社区</li>
            </ul>
        </div>

        <div class="tab_con">
            <div class="item" style="display: block;">商品介绍商品介绍</div>
            <div class="item">规格与包装规格与包装</div>
            <div class="item">售后保障售后保障</div>
            <div class="item">商品评价商品评价</div>
            <div class="item">手机社区手机社区</div>
        </div>
    </div>
    <script>
        var lili = document.querySelector('.tab_list').querySelectorAll('li');
        var item = document.querySelector('.tab_con').getElementsByClassName('item');
        for(var i = 0;i<lili.length;i++){
            lili[i].onclick = function(){
                for(var i = 0; i <lili.length;i++){
                    lili[i].setAttribute('index',i);
                    lili[i].className = ''//变色前用排他思想for循环将样式设置为空
                }
                this.className = 'bianshe';
                var index = this.getAttribute('index');
                console.log(index);
                for(var i =0;i<item.length;i++){
                    item[i].style.display = 'none';
                }
                item[index].style.display = 'block';
            }
            
        }
    </script>
</body>
</html>